﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace KinectDwa
{
    public static class TommisMouseEmulator
    {
        [DllImport("user32.dll")]
        private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);
        private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
        private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
        private static IntPtr empty = new System.IntPtr();

        public static Point Position
        {
            get
            {
                return Cursor.Position;
            }
            set
            {
                Cursor.Position = value;
            }
        }

        public static void Click()
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, empty);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, empty);
        
        }

        public static void LeftButtonDown()
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, empty);
        }

        public static void LeftButtonUp()
        {
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, empty);
        }

        private static bool isLeftButtonDown;
        public static bool IsLeftButtonDown
        {
            get
            {
                return isLeftButtonDown;
            }
            set
            {
                isLeftButtonDown = value;

                if (value == true)
                {
                    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, empty);
                }
                else
                {
                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, empty);
                }
            }
        }
    }
}
